/*! m.ximalaya.com 20-09-2017 */
!function (a) {
    jQuery.cookie = function (b, c, d) {
        if ("undefined" == typeof c) {
            var e = null;
            if (document.cookie && "" != document.cookie) for (var f = document.cookie.split(";"), g = 0; g < f.length; g++) {
                var h = jQuery.trim(f[g]);
                if (h.substring(0, b.length + 1) == b + "=") {
                    e = decodeURIComponent(h.substring(b.length + 1));
                    break
                }
            }
            return e
        }
        d = d || {}, null === c && (c = "", d = a.extend({}, d), d.expires = -1);
        var i = "";
        if (d.expires && ("number" == typeof d.expires || d.expires.toUTCString)) {
            var j;
            "number" == typeof d.expires ? (j = new Date, j.setTime(j.getTime() + 1e3 * d.expires)) : j = d.expires, i = "; expires=" + j.toUTCString()
        }
        var k = d.path ? "; path=" + d.path : "", l = d.domain ? "; domain=" + d.domain : "",
            m = d.secure ? "; secure" : "";
        document.cookie = [b, "=", encodeURIComponent(c), i, k, l, m].join("")
    };
    var b = navigator.userAgent, c = b.indexOf("MicroMessenger") > -1, d = b.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/),
        e = {
            setChannel: function (b) {
                a.cookie("from", b, {path: "/", domain: "", expires: 2592e3})
            }, autoDown: function (a) {
                var b = this.getHrefRefs(), c = [], d = b.from, e = c.indexOf(d) > -1 || "1" == b.xm;
                e && a.trigger("click")
            }, getHrefRefs: function (a) {
                var b = a || location.href, c = b.indexOf("?"), d = b.substring(b.indexOf("?") + 1), e = {}, c = 0,
                    f = "";
                d = d.split("&");
                for (var g = 0; g < d.length; g++) f = d[g], f = f.split("="), f[1] && (c = f[1].indexOf("#"), e[f[0]] = -1 == c ? f[1] : f[1].substring(0, f[1].indexOf("#")));
                return e
            }, addExtraParam: function (b, c) {
                var d = b.indexOf("?"), e = function (b, c) {
                    var d = b.split("&"), e = null;
                    sp = {};
                    for (var f = 0; f < d.length; f++) {
                        e = d[f];
                        var g = e.split("=");
                        g[0] && (sp[g[0]] = g[1])
                    }
                    return a.param(a.extend(sp, c))
                };
                if (-1 === d) {
                    var f = b.split("#");
                    return f[0] + "?" + a.param(c) + (f[1] && f[1].length > 0 ? "#" + f[1] : "")
                }
                var f = b.split("?"), g = f[1];
                if (g && "" !== g) {
                    var h = g.split("#");
                    return h.length > 1 ? f[0] + "?" + e(h[0], c) + "#" + h[1] : f[0] + "?" + e(h[0], c)
                }
                return f[0]
            }, addChannel: function (b) {
                var c = a.cookie("from");
                return c && (b = this.addExtraParam(b, {from: c})), b
            }, trackEvent: function (a) {
                window.hasOwnProperty("_hmt") && _hmt && a.category && a.action && _hmt.push(["_trackEvent", a.category || "", a.action || "", a.label || "", a.lv || ""]), window.ga && window.ga("send", "event", a.category, a.action, a.tag || "下载")
            }, init: function () {
                a(".j-down4seo").removeClass("no-event");
                var b = window.config;
                xmLog && xmLog("create", {
                    item: b.BI_PAGE,
                    itemId: b.BI_PAGE_ID
                }), xmLog("send", "event", {
                    serviceId: "viewitem",
                    item: "下载页",
                    "function": "downloadLanding"
                }), c && a(".tip-weixin").removeClass("hidden"), this.autoDown(a(".j-down4seo"))
            }, doDownload: function (a, b, c, d) {
                var e = config.ROOT_DOMAIN + "/img/v1.apk.1";
                if (this.getHrefRefs && this.getHrefRefs.from) switch (this.getHrefRefs.from.toLowerCase()) {
                    case"baidu":
                        d = "and-sem-test"
                }
                e = this.addChannel(e), this.trackEvent({
                    category: a,
                    action: b,
                    label: c,
                    tag: d
                }), this.wakeApp(function () {
                    location.href = e
                })
            }, wakeApp: function (a, b) {
                var c = "iting://open", e = b && b.source;
                if (e && (c += /\?/.test(c) ? "&source=" + e : "?source=" + e), d) location.href = c, setTimeout(function () {
                    a && a()
                }, 3e3); else {
                    var f = document.createElement("iframe");
                    f.src = c, f.style.display = "none", document.body.appendChild(f), window.setTimeout(function () {
                        document.body.removeChild(f), a && a()
                    }, 3e3)
                }
            }
        }, f = localStorage.getItem("qudaohao");
    if (f) {
        var g = f.split("=");
        2 == g.length && "from" == g[0] && (localStorage.removeItem("qudaohao"), e.setChannel(g[1]))
    } else e.getHrefRefs.from && e.setChannel(e.getHrefRefs.from);
    a(function () {
        e.init()
    })
}($);
